package com.znow.admin.system.security.controller;

import com.znow.admin.system.security.model.dto.PermissionsTreeDTO;
import com.znow.admin.system.security.model.res.PermissionPageRequest;
import com.znow.admin.system.security.model.res.PermissionRequest;
import com.znow.admin.system.security.model.vo.component.ComponentVO;
import com.znow.admin.system.security.service.SysPermissionsService;
import com.znow.common.model.CommonResult;
import com.znow.common.model.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 权限相关接口
 *
 * @author Nemo
 * @date 2022/12/19
 */
@AllArgsConstructor
@Api(value = "menu", tags = "权限菜单接口")
@RequestMapping("/sys/permissions")
@RestController
public class MenuController {

    private final SysPermissionsService sysPermissionsService;

    @ApiOperation("获取系统菜单接口")
    @PostMapping("/menu")
    public CommonResult<List<ComponentVO>> getTreeMenu() {
        return CommonResult.success(sysPermissionsService.getMenu(1L));
    }

    @ApiOperation("获取菜单列表接口")
    @PostMapping("/list")
    public CommonResult<PageResult<PermissionsTreeDTO>> getPermissionsList(PermissionPageRequest request) {
        return CommonResult.success(sysPermissionsService.getPagePermissionsList(request));
    }

    @ApiOperation("添加菜单接口")
    @PostMapping("/add")
    public CommonResult<Boolean> addPermissions(@RequestBody PermissionRequest permissionRequest) {
        return CommonResult.success(sysPermissionsService.addPermissions(permissionRequest));
    }

    @ApiOperation(value = "获取权限列表")
    @PostMapping("/menu/get")
    public CommonResult<?> getPermissions() {
        return CommonResult.success();
    }

    @PostMapping("/menu/delete")
    public CommonResult<?> deletePermissions() {
        return CommonResult.success();
    }

}
